package com.lagou.edu.controller;

import com.lagou.edu.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response, String username, String password){
        if (loginService.login(username,password)) {
            HttpSession session = request.getSession();
            session.setAttribute("username",username);//在session中存入用户信息，方便后续验证
            return "redirect:/resume/list";
        }
        return "loginFailed";
    }
}
